package de.game;

import java.io.Serializable;
import java.util.ArrayList;

import de.game.objects.GameObject;
import de.game.objects.Monster;
import de.game.objects.Player;


public class Level implements Serializable{

	
	/**
	 * 
	 */
	private static final long serialVersionUID = -1952664334191749590L;
	private int[][] logicGrid;
	private int id;
	private static int number = 1;
	private String name;
	private int difficulty = 0;
	private int width;
	private int height;
	private ArrayList<Monster> monster = new ArrayList<Monster>();
	private ArrayList<Player> player = new ArrayList<Player>();
	private ArrayList<GameObject> objects = new ArrayList<GameObject>();
	private int[] ziel = new int[2];
	
	/**
	 * erstellt neues Level mit neuer ID
	 * @param width
	 * @param height
	 */
	public Level(int width, int height){
		setLogicGrid(new int[width][height]);
		this.width = width;
		this.height = height;
		id = number;
		number++;
	}
	
	
	
	public Level(){
	}
	
	
	
	public int getPlayerIDfromLocation(int x, int y){
		for(Player p : player){
			if(p.getCurrentLocation()[0]==x && p.getCurrentLocation()[1]==y){
				return p.getId();
			}
		}
		return -1;
	}
	
	public Monster getMonsterFromID(int id){
		for(Monster a : monster){
			if(a.getId() == id){
				return a;
			}
		}
		// throw Monster not found Exception
		return null;
	}
	
	@Override
	public boolean equals(Object t){
		return((Level)t).getId() == this.getId();
	}

	public ArrayList<Monster> getMonsters() {
		return monster;
	}



	public void setMonsters(ArrayList<Monster> monsters) {  
				this.monster = monsters;
	}



	public ArrayList<Player> getPlayers() {
		return player;
	}



//	public void setPlayers(ArrayList<Player> players) {
//		ArrayList<Player> playersTemp = new ArrayList<Player>();
//		for(Player a : players){
//			Player p = a.deepCopy();
//			playersTemp.add(p);
//		}
//		this.player = players;
//	}



	public ArrayList<GameObject> getObjects() {
		return objects;
	}



	public void setGameObjects(ArrayList<GameObject> objects) {
		this.objects = objects;
	}



	public int getDifficulty() {
		return difficulty;
	}



	public void setDifficulty(int difficulty) {
		this.difficulty = difficulty;
	}





	public String getName() {
		return name;
	}



	public void setName(String name) {
		this.name = name;
	}



	public int[][] getLogicGrid() {
		return logicGrid;
	}



	public static int getNumber() {
		return number;
	}


	public static void setNumber(int number) {
		Level.number = number;
	}


	public void setLogicGrid(int[][] logicGrid) {
		this.logicGrid = logicGrid;
	}
	
	@Override
	public String toString(){
		String temp = "|ID: "+getId()+"|Name: "+name+"|Difficulty: "+difficulty + "|Breite: "
				+ width+", 0 bis "+(width-1)+ "|Hoehe: "+ height+", 0 bis "+(height-1)+"\n"+
				"|Anzahl der Monster: "+monster.size()+ "|Anzahl der Spieler: "+ player.size()+ "|Anzahl der Objekte: "+ objects.size();
		for(int i = 0; i < height; i++){
			temp = temp + "|\n";
			for(int j = 0; j < width; j++){
				temp = temp + "|"+ logicGrid[j][i];
			}
		}
		return temp;
	}



	public int getId() {
		return id;
	}



	public void setId(int id) {
		this.id = id;
	}


	public int getMonsterIDfromLocation(int x, int y) {
		for(Monster p : monster){
			if(p.getCurrentLocation()[0]== x && p.getCurrentLocation()[1]==y){
				return p.getId();
			}
		}
		return -1;
	}


	public int[] getZiel() {
		return ziel;
	}


	public void setZiel(int[] ziel) {
		this.ziel = ziel;
	}
	public int getWidth() {
		return width;
	}


	public void setWidth(int width) {
		this.width = width;
	}


	public int getHeight() {
		return height;
	}


	public void setHeight(int height) {
		this.height = height;
	}
	
}
